package top.laoshuzi.designpatterns.base.created.prototype.kotlin

/**
 * 原型管理器
 */
class PrototypeManager {

    companion object {
        val map = HashMap<String, Prototype>()

        fun registerPrototype(prototypeId: String, prototype: Prototype) {
            map.put(prototypeId, prototype)
        }

        fun unregisterPrototype(prototypeId: String) {
            map.remove(prototypeId)
        }

        fun getPrototype(prototypeId: String): Prototype {
            val prototype = map.get(prototypeId)
            prototype ?: throw Exception("原型" + prototypeId + "未注册或已销毁")
            return prototype.clone()
        }
    }

}